package com.qa.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.qa.pojo.Demand;
import com.qa.pojo.Users;
import com.qa.pojo.ZNode;
import com.qa.pojo.weekplan;
import com.qa.pojo.weekplanJS;
import com.qa.pojo.weekplanStatistics;
import com.qa.service.IWeekAndMonthService;
import com.sun.org.apache.bcel.internal.generic.NEW;

@Controller
@RequestMapping("/weekAndMonth")
public class weekAndMonthPlanController {
	@Resource
	private IWeekAndMonthService iWeekAndMonthService;
	Logger logger = Logger.getLogger(this.getClass());

	/**
	 * 导出excel==首页的，能多选导出
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/exportChecked")
	@ResponseBody
	public void exportChecked(HttpServletRequest request,
			HttpServletResponse response) {
		response.setStatus(200);
		Gson gson = new Gson();
		try {
			int thisYear = request.getParameter("thisYear") == null ? 1900
					: Integer.valueOf(request.getParameter("thisYear"));
			String currentEditInfo = URLDecoder.decode(
					request.getParameter("exportData"), "utf-8");
			List<weekplanStatistics> weekplanSta = gson.fromJson(
					currentEditInfo, new TypeToken<List<weekplanStatistics>>() {
					}.getType());
			List<Map<String, Object>> listAllList = new ArrayList<>();
			for (weekplanStatistics wStatistics : weekplanSta) {
				Map<String, Object> map = new HashMap<>();
				List<weekplan> list = this.iWeekAndMonthService
						.getEditWeekPlan(wStatistics.getWeeknum(),
								wStatistics.getPublishid(), thisYear);
				map.put("huizong", wStatistics);
				map.put("mingxi", list);
				listAllList.add(map);
			}
			// 开始导出，获取模板路径
			String templatePath = request.getSession().getServletContext()
					.getRealPath("template/weekplantemp.xls");

			// 写入工作簿
			this.iWeekAndMonthService.exportDataAll(listAllList, templatePath,
					response);
		} catch (UnsupportedEncodingException e) {

			e.printStackTrace();
			logger.error(e.getMessage());
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
		}
	}

	/**
	 * 导出excel
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/exportWeekPlan")
	@ResponseBody
	public void exportWeekPlan(HttpServletRequest request,
			HttpServletResponse response) {
		response.setStatus(200);
		Gson gson = new Gson();
		try {
			int usersid = ((Users) request.getSession().getAttribute("user"))
					.getUsersid();
			Double selfperSum = 0.00;
			Double bossperSum = 0.00;
			String weekplans = request.getParameter("weekplans");
			weekplans = URLDecoder.decode(request.getParameter("weekplans"),
					"UTF-8");

			List<weekplanJS> list = gson.fromJson(weekplans,
					new TypeToken<List<weekplanJS>>() {
					}.getType());

			String currentEditInfo = URLDecoder.decode(
					request.getParameter("currentEditInfo"), "utf-8");
			weekplanStatistics weekplanSta = gson.fromJson(currentEditInfo,
					new TypeToken<weekplanStatistics>() {
					}.getType());
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			SimpleDateFormat myFmt = new SimpleDateFormat("yyyy-MM-dd");
			List<weekplan> weekplansList = new ArrayList<weekplan>();

			for (weekplanJS weekplanjs : list) {
				weekplan weekplan1 = new weekplan();
				String begintime = calendar.get(Calendar.YEAR) + "-"
						+ weekplanjs.getBeginmonth1() + "-"
						+ weekplanjs.getBegindate1();
				String endtime = calendar.get(Calendar.YEAR) + "-"
						+ weekplanjs.getEndmonth1() + "-"
						+ weekplanjs.getEnddate1();
				weekplan1.setBegintime(myFmt.parse(begintime));
				weekplan1.setEndtime(myFmt.parse(endtime));
				weekplan1.setBossper(weekplanjs.getBossper1());
				weekplan1.setBossremark(weekplanjs.getBossremark1());
				weekplan1.setEffect(weekplanjs.getEffect1());
				weekplan1.setEffectboss(weekplanjs.getEffectboss1());
				weekplan1.setEfficiency(weekplanjs.getEfficiency1());
				weekplan1.setEfficiencyboss(weekplanjs.getEfficiencyboss1());
				weekplan1.setKeyresults(weekplanjs.getKeyresult1());
				weekplan1.setKeyresultsper(weekplanjs.getKeyresultper1());
				weekplan1.setKeyresultstandard(weekplanjs.getKeyresultstand1());
				weekplan1.setNeedperson(weekplanjs.getNeedpersonal1());
				weekplan1.setObject(weekplanjs.getWeekObject1());
				weekplan1.setResultremark(weekplanjs.getResultremark1());
				weekplan1.setSelfper(weekplanjs.getSelfper1());
				weekplan1.setSourceid(weekplanjs.getResultSource1());
				weekplan1.setLastmodified(usersid);
				selfperSum += weekplan1.getSelfper();
				bossperSum += weekplan1.getBossper();
				weekplansList.add(weekplan1);
			}
			if (weekplansList.size() > 0) {
				// 开始导出，获取模板路径
				String templatePath = request.getSession().getServletContext()
						.getRealPath("template/weekplantemp.xls");
				// 写入工作簿
				this.iWeekAndMonthService.exportData(weekplansList,
						weekplanSta, selfperSum, bossperSum, templatePath,
						response);
			}
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error(e.getMessage());
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
		}
	}

	/**
	 * 插入项目 作者duvee 时间：2018-0615
	 */

	@RequestMapping(value = "/editDemand", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> editDemand(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		response.setStatus(200);
		Gson gson = new Gson();
		try {
			int usersid = ((Users) request.getSession().getAttribute("user"))
					.getUsersid();
			String beginTimeadd = request.getParameter("beginTimeadd") == null ? null
					: URLDecoder.decode(request.getParameter("beginTimeadd"),
							"utf-8");
			String endTimeadd = request.getParameter("endTimeadd") == null ? null
					: URLDecoder.decode(request.getParameter("endTimeadd"),
							"utf-8");
			String demandContent = request.getParameter("demandContent") == null ? null
					: URLDecoder.decode(request.getParameter("demandContent"),
							"utf-8");
			int statusFordemandadd = Integer.valueOf(request
					.getParameter("statusFordemandadd"));
			int id = Integer.valueOf(request.getParameter("id"));
			int editDemand = this.iWeekAndMonthService.editDemand(beginTimeadd,
					endTimeadd, demandContent, statusFordemandadd, id);
			if (editDemand < 1) {
				resultMap.put("tag", "error");
				resultMap.put("msg", "项目编辑失败！");
				return resultMap;
			}
			resultMap.put("tag", "success");
			resultMap.put("msg", "项目修改成功！");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error(e.getMessage());
			resultMap.put("tag", "error");
			resultMap.put("msg", "编码格式有误！请联系管理员！");
			return resultMap;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
			resultMap.put("tag", "error");
			resultMap.put("msg", "系统异常，请联系管理员！");
			return resultMap;
		}
		return resultMap;
	}

	/**
	 * 插入项目 作者duvee 时间：2018-0615
	 */

	@RequestMapping(value = "/insertDemand", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> insertDemand(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		response.setStatus(200);
		Gson gson = new Gson();
		try {
			int usersid = ((Users) request.getSession().getAttribute("user"))
					.getUsersid();
			String beginTimeadd = request.getParameter("beginTimeadd") == null ? null
					: URLDecoder.decode(request.getParameter("beginTimeadd"),
							"utf-8");
			String endTimeadd = request.getParameter("endTimeadd") == null ? null
					: URLDecoder.decode(request.getParameter("endTimeadd"),
							"utf-8");
			String demandContent = request.getParameter("demandContent") == null ? null
					: URLDecoder.decode(request.getParameter("demandContent"),
							"utf-8");
			int statusFordemandadd = Integer.valueOf(request
					.getParameter("statusFordemandadd"));

			int insertDemand = this.iWeekAndMonthService
					.insertDemand(beginTimeadd, endTimeadd, demandContent,
							statusFordemandadd);
			if (insertDemand < 1) {
				resultMap.put("tag", "error");
				resultMap.put("msg", "项目添加失败！");
				return resultMap;
			}
			resultMap.put("tag", "success");
			resultMap.put("msg", "项目添加成功！");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error(e.getMessage());
			resultMap.put("tag", "error");
			resultMap.put("msg", "编码格式有误！请联系管理员！");
			return resultMap;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
			resultMap.put("tag", "error");
			resultMap.put("msg", "系统异常，请联系管理员！");
			return resultMap;
		}
		return resultMap;
	}

	/**
	 * 插入对应的周计划 作者duvee 时间：2017-0727
	 */

	@RequestMapping(value = "/insertWeekPlan", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> insertWeekPlan(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		response.setStatus(200);
		Gson gson = new Gson();
		try {
			int usersid = ((Users) request.getSession().getAttribute("user"))
					.getUsersid();
			int weeknum = Integer.valueOf(request.getParameter("weeknum"));
			System.out.println(request.getParameter("currenteditUsersid"));
			int currenteditUsersid = request.getParameter("currenteditUsersid") == null
					|| request.getParameter("currenteditUsersid")
							.equals("null")
					|| request.getParameter("currenteditUsersid").trim()
							.equals("") ? -1 : Integer.valueOf(request
					.getParameter("currenteditUsersid"));

			if (currenteditUsersid == -1) {
				int weekIsExist = this.iWeekAndMonthService
						.selectWeekNumIsExist(weeknum, usersid);
				if (weekIsExist > 0) {
					resultMap.put("tag", "error");
					resultMap.put("msg", "该周已经存在，您可以在查询里面进行编辑。");
					return resultMap;
				}
				currenteditUsersid = usersid;
			} else {
				int oldWeeknum = request.getParameter("oldWeeknum") == null
						|| request.getParameter("oldWeeknum").equals("null")
						|| request.getParameter("oldWeeknum").trim().equals("") ? -1
						: Integer.valueOf(request.getParameter("oldWeeknum"));
				int deleteExistWeek = this.iWeekAndMonthService
						.deleteExistWeek(oldWeeknum, currenteditUsersid);
				logger.info("当前删除的周计划条数为" + deleteExistWeek);
			}
			String weekplans = URLDecoder.decode(
					request.getParameter("weekplans"), "utf-8");
			List<weekplanJS> list = gson.fromJson(weekplans,
					new TypeToken<List<weekplanJS>>() {
					}.getType());
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			SimpleDateFormat myFmt = new SimpleDateFormat("yyyy-MM-dd");
			List<weekplan> weekplansList = new ArrayList<weekplan>();
			for (weekplanJS weekplanjs : list) {
				weekplan weekplan1 = new weekplan();
				String begintime = calendar.get(Calendar.YEAR) + "-"
						+ weekplanjs.getBeginmonth1() + "-"
						+ weekplanjs.getBegindate1();
				String endtime = calendar.get(Calendar.YEAR) + "-"
						+ weekplanjs.getEndmonth1() + "-"
						+ weekplanjs.getEnddate1();
				weekplan1.setBegintime(myFmt.parse(begintime));
				weekplan1.setEndtime(myFmt.parse(endtime));
				weekplan1.setBossper(weekplanjs.getBossper1());
				weekplan1.setBossremark(weekplanjs.getBossremark1());
				weekplan1.setEffect(weekplanjs.getEffect1());
				weekplan1.setEffectboss(weekplanjs.getEffectboss1());
				weekplan1.setEfficiency(weekplanjs.getEfficiency1());
				weekplan1.setEfficiencyboss(weekplanjs.getEfficiencyboss1());
				weekplan1.setKeyresults(weekplanjs.getKeyresult1());
				weekplan1.setKeyresultsper(weekplanjs.getKeyresultper1());
				weekplan1.setKeyresultstandard(weekplanjs.getKeyresultstand1());
				weekplan1.setNeedperson(weekplanjs.getNeedpersonal1());
				weekplan1.setObject(weekplanjs.getWeekObject1());
				weekplan1.setResultremark(weekplanjs.getResultremark1());
				weekplan1.setSelfper(weekplanjs.getSelfper1());
				weekplan1.setSourceid(weekplanjs.getResultSource1());
				weekplan1.setUsersid(currenteditUsersid);
				weekplan1.setWeeknum(weeknum);
				weekplan1.setLastmodified(usersid);
				weekplansList.add(weekplan1);
			}

			int insertweekplan = this.iWeekAndMonthService
					.insertWeekPlan(weekplansList);
			if (insertweekplan < 1) {
				resultMap.put("tag", "error");
				resultMap.put("msg", "周计划插入失败！");
				return resultMap;
			}
			resultMap.put("tag", "success");
			if (currenteditUsersid == -1) {
				resultMap.put("msg", "周计划添加成功！");
			} else {
				resultMap.put("msg", "周计划编辑成功！");
			}
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error(e.getMessage());
			resultMap.put("tag", "error");
			resultMap.put("msg", "编码格式有误！请联系管理员！");
			return resultMap;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
			resultMap.put("tag", "error");
			resultMap.put("msg", "系统异常，请联系管理员！");
			return resultMap;
		}
		return resultMap;
	}

	/**
	 * 获取将要编辑的对应的人员的周计划
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("/getEditWeekPlan")
	@ResponseBody
	public Map<String, Object> getEditWeekPlan(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		response.setStatus(200);
		try {
			int thisYear = request.getParameter("thisYear") == null ? 1900
					: Integer.valueOf(request.getParameter("thisYear"));
			int weeknum = request.getParameter("weeknum") == null ? 0 : Integer
					.valueOf(request.getParameter("weeknum"));
			int publish = request.getParameter("publish") == null ? 0 : Integer
					.valueOf(request.getParameter("publish"));
			List<weekplan> list = this.iWeekAndMonthService.getEditWeekPlan(
					weeknum, publish, thisYear);
			if (list.size() <= 0) {
				resultMap.put("tag", "error");
				resultMap.put("msg", "无查询结果");
				return resultMap;
			}
			List<Map<String, Object>> listMaps = new ArrayList<>();
			for (weekplan weekplan1 : list) {
				Map<String, Object> map = new HashMap<>();
				map.put("resultSource1", weekplan1.getSourceid());
				Calendar calendar = Calendar.getInstance();
				calendar.setTime(weekplan1.getBegintime());
				int beginmonth = calendar.get(Calendar.MONTH) + 1;
				int begindate = calendar.get(Calendar.DAY_OF_MONTH);
				calendar.setTime(weekplan1.getEndtime());
				int endmonth = calendar.get(Calendar.MONTH) + 1;
				int enddate = calendar.get(Calendar.DAY_OF_MONTH);
				map.put("beginmonth1", beginmonth);
				map.put("begindate1", begindate);
				map.put("endmonth1", endmonth);
				map.put("enddate1", enddate);
				map.put("efficiency1", weekplan1.getEfficiency());
				map.put("effect1", weekplan1.getEffect());
				map.put("efficiencyboss1", weekplan1.getEfficiencyboss());
				map.put("effectboss1", weekplan1.getEffectboss());
				map.put("weekObject1", weekplan1.getObject());
				map.put("keyresult1", weekplan1.getKeyresults());
				map.put("needpersonal1", weekplan1.getNeedperson());
				map.put("keyresultper1", weekplan1.getKeyresultsper());
				map.put("keyresultstand1", weekplan1.getKeyresultstandard());
				map.put("selfper1", weekplan1.getSelfper());
				map.put("resultremark1", weekplan1.getResultremark());
				map.put("bossper1", weekplan1.getBossper());
				map.put("bossremark1", weekplan1.getBossremark());
				listMaps.add(map);
			}
			resultMap.put("tag", "success");
			resultMap.put("editInfo", listMaps);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
			resultMap.put("tag", "error");
			resultMap.put("msg", e.getMessage());
			return resultMap;
		}
		return resultMap;
	}

	/**
	 * 根据人员获取部门树列表。
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("/selectDeptOrTeam")
	@ResponseBody
	public Map<String, Object> selectDeptOrTeam(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		response.setStatus(200);
		try {
			int usersid = ((Users) request.getSession().getAttribute("user"))
					.getUsersid();
			List<ZNode> zNodes = new ArrayList<ZNode>();
			zNodes = this.iWeekAndMonthService.selectDeptOrTeam(usersid);
			List<Map<String, Object>> zNodeList = new ArrayList<>();
			for (ZNode znode : zNodes) {
				Map<String, Object> map = new HashMap<>();
				if (znode.getIsDeptOrTeam() == 3) {
					// 如果没有上级，就干掉他
					if (znode.getpId() == 0) {
						continue;
					}
				}
				// 根据 isopen 0代表打开，1代表关闭
				if (znode.getIsopen() == 0) {
					znode.setOpen(true);
				}
				map.put("pId", znode.getpId());
				map.put("name", znode.getName());
				map.put("open", znode.isOpen());
				map.put("isDeptOrTeam", znode.getIsDeptOrTeam());
				map.put("selectID", znode.getSelectID());
				if (znode.getIconOpen() != null) {
					map.put("iconOpen", znode.getIconOpen());
				}
				if (znode.getIconClose() != null) {
					map.put("iconClose", znode.getIconClose());
				}
				if (znode.getIcon() != null) {
					map.put("icon", znode.getIcon());
				}
				map.put("id", znode.getId());
				zNodeList.add(map);
			}
			resultMap.put("tag", "success");
			resultMap.put("zNodes", zNodeList);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
		}
		return resultMap;
	}

	/**
	 * 查询项目
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@SuppressWarnings("deprecation")
	@RequestMapping("/selectDemand")
	@ResponseBody
	public Map<String, Object> selectDemand(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		response.setStatus(200);
		int usersid = ((Users) request.getSession().getAttribute("user"))
				.getUsersid();
		try {
			// 默认0，不看过期的项目
			int isGuoQi = 0;
			Boolean onlySeeSelf = Boolean.valueOf(request
					.getParameter("onlySeeSelf"));
			if (onlySeeSelf) {
				isGuoQi = 1;
			}

			int statusFordemand = Integer.valueOf(request
					.getParameter("statusFordemand"));
			String beginTime = request.getParameter("beginTime") == null ? null
					: URLDecoder.decode(request.getParameter("beginTime"),
							"utf-8");
			String endTime = request.getParameter("endTime") == null ? null
					: URLDecoder.decode(request.getParameter("endTime"),
							"utf-8");
			System.out.println(beginTime + "====" + endTime);

			List<Demand> list = this.iWeekAndMonthService.selectDemand(
					beginTime, endTime, isGuoQi, statusFordemand);
			if (list.size() > 0) {
				resultMap.put("tag", "success");
				resultMap.put("data", list);
			}
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error(e.getMessage());
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
		}
		return resultMap;
	}

	/**
	 * 查询对应人员的周计划统计
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("/selectWeekPlan")
	@ResponseBody
	public Map<String, Object> selectWeekPlan(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		response.setStatus(200);
		int usersid = ((Users) request.getSession().getAttribute("user"))
				.getUsersid();
		try {
			// 默认0，是不只查询自己
			int isSelf = 0;
			Boolean onlySeeSelf = Boolean.valueOf(request
					.getParameter("onlySeeSelf"));
			if (onlySeeSelf) {
				isSelf = 1;
			}
			int isDeptOrTeam = request.getParameter("isDeptOrTeam") == null ? 0
					: Integer.valueOf(request.getParameter("isDeptOrTeam"));
			String beginTime = request.getParameter("beginTime") == null ? null
					: URLDecoder.decode(request.getParameter("beginTime"),
							"utf-8");
			String endTime = request.getParameter("endTime") == null ? null
					: URLDecoder.decode(request.getParameter("endTime"),
							"utf-8");
			// 改动，从开始结束时间变更为计算开始和技术周数，取中间的周计划
			int beginweeknum = 0, endweeknum = 99;
			SimpleDateFormat myFmt = new SimpleDateFormat("yyyy-MM-dd");
			int beginYear = 1900, endYear = 2999;
			if (!beginTime.equals("null")) {
				Date date = myFmt.parse(beginTime);
				Calendar calendar = Calendar.getInstance();
				calendar.setTime(date);
				beginYear = calendar.get(Calendar.YEAR);
				int begintian = calendar.get(Calendar.DAY_OF_YEAR);
				calendar.set(beginYear, 0, 1);
				int firstDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
				int firstday = calendar.get(Calendar.DAY_OF_YEAR);
				double d1 = begintian - firstday + firstDayOfWeek;
				beginweeknum = (int) Math.ceil(d1 / 7);
				System.out.println(beginweeknum + "---------开始周数-------");
			}
			if (!endTime.equals("null")) {
				Date date = myFmt.parse(endTime);
				Calendar calendar = Calendar.getInstance();
				calendar.setTime(date);
				endYear = calendar.get(Calendar.YEAR);
				int endtian = calendar.get(Calendar.DAY_OF_YEAR);
				calendar.set(endYear, 0, 1);
				int firstDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
				int firstday = calendar.get(Calendar.DAY_OF_YEAR);
				double d1 = endtian - firstday + firstDayOfWeek;
				endweeknum = (int) Math.ceil(d1 / 7);
				System.out.println(endweeknum + "---------结束周数-------");
			}
			List<String> group = request.getParameter("examineGroup") == null ? null
					: Arrays.asList(URLDecoder.decode(
							request.getParameter("examineGroup"), "UTF-8"));
			List<Integer> trueGroup = null;
			if (group.size() > 0 && group.get(0).length() > 0) {
				trueGroup = new ArrayList<Integer>();
				String[] groupInt = group.get(0).trim().split(",");
				for (String a : groupInt) {
					trueGroup.add(Integer.valueOf(a));
				}
			}
			int selectPerson = request.getParameter("selectPerson") == null
					|| request.getParameter("selectPerson").equals("null") ? 999999
					: Integer.valueOf(request.getParameter("selectPerson"));
			List<weekplanStatistics> list = this.iWeekAndMonthService
					.selectWeekPlan(isSelf, usersid, isDeptOrTeam,
							beginweeknum, endweeknum, trueGroup, selectPerson,
							beginYear, endYear);
			if (list.size() > 0) {
				resultMap.put("tag", "success");
				resultMap.put("data", list);
			}
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error(e.getMessage());
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
		}
		return resultMap;
	}
}